package com.atguigu.lease.web.app.service.impl;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.atguigu.lease.web.app.service.SmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SmsServiceImpl implements SmsService {
    @Autowired
    Client client;

    //    发送短信
    @Override
    public void sendMsg(String phone, String code) {
        try {
            SendSmsRequest sendSmsRequest =new SendSmsRequest();
            sendSmsRequest.setSignName("阿里云短信测试");// 签名名称
            sendSmsRequest.setTemplateCode("SMS_154950909");// 模板code
            sendSmsRequest.setPhoneNumbers(phone);// 手机号
            sendSmsRequest.setTemplateParam("{\"code\":\""+code+"\"}");//  验证码
            SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
